package action;

import bean.DeptBean;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import service.DeptService;

import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.List;

/**
 * @Author: zhaojg
 * @Description
 * @Date: Created in 10:35 2018/4/27
 * @Modified by:
 */
@SuppressWarnings("serial")
public class DeptAction extends ActionSupport {

    private String result;

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    DeptService deptService = new DeptService();

    List<DeptBean> deptList = null;

    public String getDeptZTree() throws UnsupportedEncodingException {
        try {
            List<DeptBean> deptList = deptService.selectDeptTree();

            for (DeptBean deptBean : deptList) {
                String name = deptBean.getName();

                if (name.equals(new String("省行部门".getBytes(), "UTF-8"))) {
                    deptBean.setNocheck(true);
                }
                if (name.equals(new String("西安地区支行".getBytes(), "UTF-8"))) {
                    deptBean.setNocheck(true);
                }
                if (name.equals(new String("西安城区直管支行".getBytes(), "UTF-8"))) {
                    deptBean.setNocheck(true);
                }
                if (name.equals(new String("地市分行".getBytes(), "UTF-8"))) {
                    deptBean.setNocheck(true);
                }
            }
            JSONArray arr = JSONArray.fromObject(deptList);
            result = arr.toString();
            ActionContext.getContext().put("result", result);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }

    public static void main(String[] args) {
        boolean equals = StringUtils.equals("陕西全辖", "陕西全辖");
        System.out.println("equals = " + equals);
    }

}
